<?xml version="1.0" encoding="UTF-8"?>
<project name="Optimizer" default="kit">

	<property name="configuration" value="release" />

	<path id="project.class.path">
		<pathelement location="bin" />
		<fileset dir="dependencies">
			<include name="**/*.jar"/>
		</fileset>
	</path>

	<target name="compile">
		<condition property="isDebug">
			<equals arg1="${configuration}" arg2="debug" />
		</condition>
		<mkdir dir="bin" />
		<delete>
			<fileset dir="bin" includes="**/*" />
		</delete>
		<!-- Why isn't there inline expression evaluation in ant?? -->
		<condition property="debug" value="on">
			<equals arg1="${configuration}" arg2="debug" />
		</condition>
		<!-- Optimizer -->
		<javac srcdir="src" destdir="bin" debug="${debug}">
			<classpath refid="project.class.path"/>
		</javac>
	</target>

	<target name="test" depends="compile">
		<java
			failonerror="true"
			classname="org.junit.runner.JUnitCore">
			<classpath refid="project.class.path"/>
			<arg value="org.dyndns.opendemogroup.optimizer.TestSuite" />
		</java>
	</target>

	<target name="documentation" depends="test">
		<mkdir dir="docs" />
		<delete>
			<fileset dir="docs" includes="**/*" />
		</delete>
		<javadoc
				sourcepath="src"
				destdir="docs"
				packagenames="org.dyndns.opendemogroup.*">
			<classpath refid="project.class.path"/>
		</javadoc>
	</target>

	<target name="kit" depends="documentation">
		<mkdir dir="kit" />
		<delete>
			<fileset dir="kit" includes="**/*" />
		</delete>
		<!-- TODO: encode version number in output files -->
		<jar basedir="bin" destfile="kit/optimizer.jar" />
		<zip basedir="docs" destfile="kit/optimizer-docs.zip" />
		<zip basedir="src" destfile="kit/optimizer-src.zip" />
	</target>

	<target name="run" depends="test">
		<parallel failonany="true">
			<java
				failonerror="true"
				output="run1.out"
				error="run1.err"
				classname="org.dyndns.opendemogroup.optimizer.ConsoleRunner">
				<classpath refid="project.class.path"/>
				<arg value="profiles/assignment 1/OneMax.xml" />
				<arg value="profiles/assignment 1/SimpleMax.xml" />
				<arg value="profiles/assignment 1/TSP/SimpleShape.xml" />
				<arg value="profiles/assignment 1/TSP/Berlin52-SlidingBias.xml" />
				<arg value="profiles/assignment 2/LABS/TwoPoint.xml" />
				<arg value="profiles/assignment 2/LABS/LongestAlternatingSequence.xml" />
				<arg value="profiles/assignment 2/LABS/RandomParentAllele.xml" />
			</java>
			<java
				failonerror="true"
				output="run2.out"
				error="run2.err"
				classname="org.dyndns.opendemogroup.optimizer.ConsoleRunner">
				<classpath refid="project.class.path"/>
				<arg value="profiles/assignment 1/HardMax.xml" />
				<arg value="profiles/assignment 1/OneMin.xml" />
				<arg value="profiles/assignment 2/HyperSphere3.xml" />
				<arg value="profiles/assignment 2/HyperSphere20.xml" />
				<arg value="profiles/assignment 1/TSP/Berlin52-Tournament.xml" />
			</java>
			<java
				failonerror="true"
				output="run3.out"
				error="run3.err"
				classname="org.dyndns.opendemogroup.optimizer.ConsoleRunner">
				<classpath refid="project.class.path"/>
				<arg value="profiles/assignment 2/FlatCone.xml" />
				<arg value="profiles/assignment 1/TSP/Berlin52-Rank.xml" />
			</java>
			<java
				failonerror="true"
				output="run4.out"
				error="run4.err"
				classname="org.dyndns.opendemogroup.optimizer.ConsoleRunner">
				<classpath refid="project.class.path"/>
				<arg value="profiles/assignment 2/Rastrigin/Simple (4,10)-ES.xml" />
				<arg value="profiles/assignment 2/Rastrigin/Nested [2,6(4,10)^40]-ES.xml" />
				<arg value="profiles/assignment 2/Rastrigin/Nested [2,6(4,10)^400]-ES.xml" />
				<arg value="profiles/assignment 2/Rastrigin/Nested [2,6(4,10)^20]-ES.xml" />
				<arg value="profiles/assignment 2/Rastrigin/Nested [2,6(4,10)^10]-ES.xml" />
				<arg value="profiles/assignment 2/Rastrigin/Nested [2,6(5,20)^10]-ES.xml" />
			</java>
		</parallel>
	</target>

</project>